﻿using Furion.EventBus;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;

namespace Furion.CMS.Core.EventSource
{
    public class OnTriggerOuterEvent : IEventSource
    {
        /// <summary>
        /// 全局触发消息
        /// </summary>
        /// <param name="category"></param>
        public OnTriggerOuterEvent(OuterEventCategory category)
        {
            Category = category;
            Payload = $"{DateTime.UtcNow:yyyy-MM-dd HH:mm:ss}"; // 添加默认载体内容避免空值
            CreatedTime = DateTime.UtcNow;
            EventId = EventIdConsts.TriggerOuterEvent;
        }

        /// <summary>
        /// 指定用户触发消息
        /// </summary>
        /// <param name="category"></param>
        /// <param name="userId"></param>
        public OnTriggerOuterEvent(OuterEventCategory category, string userId) : this(category)
        {
            UserId = userId;
        }

        /// <summary>
        /// 指定用户通知消息
        /// </summary>
        /// <param name="category"></param>
        /// <param name="userId"></param>
        /// <param name="payload"></param>
        public OnTriggerOuterEvent(OuterEventCategory category, string userId, object payload)
            : this(category, userId)
        {
            Payload = payload;
        }

        /// <summary>
        /// 外部事件类型
        /// </summary>
        public OuterEventCategory Category { get; }
        /// <summary>
        /// 触发人id
        /// </summary>
        public string UserId { get; }

        public string EventId { get; }

        public object Payload { get; }

        public DateTime CreatedTime { get; }

        public CancellationToken CancellationToken { get; }
    }
}
